package com.atguigu.blog.service.impl;

import ch.qos.logback.core.util.DirectJson;
import com.atguigu.blog.entity.User;
import com.atguigu.blog.mapper.UserMapper;
import com.atguigu.blog.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.util.Date;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    /**
     * 2.1 用户登录
     * @author Petrichor
     * @date 2023/10/24 10:50
     **/
    @Override
    public User findUserByUP(User user) {
        // SpringBoot自带的加密
        String md5Password = DigestUtils.md5DigestAsHex(user.getPassword().getBytes());
        user.setPassword(md5Password);
        return userMapper.findUserByUP(user);
    }
    /**
     * //5.1 用户信息展现
     * @author Petrichor
     * @date 2023/10/24 21:04
     **/
    @Override
    public User findUserById(Long uid) {
        User user = userMapper.findUserById(uid);
        user.setPassword("不能回显");
        return user;
    }
    /**
     * 5.2 用户信息修改
     * @author Petrichor
     * @date 2023/10/25 08:44
     **/
    @Override
    public void updateUserById(User user) {
        user.setUpdateTime(new Date());
        userMapper.updateUserById(user);
    }

}
